//
//  WorkHomeVC.m
//  XLDoctor
//
//  Created by longma on 2018/7/27.
//  Copyright © 2018年 XLH. All rights reserved.
//mj关于我们

#import "AboutController.h"
#import "UpdateController.h"

@interface AboutController ()
@property (weak, nonatomic) IBOutlet MJUICellImageTextView *updateItemView;
@property (weak, nonatomic) IBOutlet UILabel *versionLabel;
@property (weak, nonatomic) IBOutlet UIImageView *logoImageView;
@property (weak, nonatomic) IBOutlet UILabel *tokenLabel;

@end

@implementation AboutController


- (void)viewDidLoad {
    self.backgroundColorType = BackgroundColorTypeGray;
    [super viewDidLoad];
   
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
}

- (void)mj_setUI{
    [super mj_setUI];
    
    self.mj_titleLocalizable = @"About App";
    self.versionLabel.text = [@"Version " stringByAppendingString:[NSString mj_appVersion]];
    if(self.updateData){
        [self updateUI];
    }else{
        MJWeakSelf
        [HealthHelper checkUpdateBlock:^(NSDictionary *data) {
            if(data){
                weakSelf.updateData = data;
                [weakSelf updateUI];
            }
        }];
    }
    //初始化一个长按手势
    [self.logoImageView setUserInteractionEnabled:YES];
    UILongPressGestureRecognizer *longPressGest = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressView:)];
    //长按等待时间
    longPressGest.minimumPressDuration = 3;
        //长按时候,手指头可以移动的距离
    [self.logoImageView addGestureRecognizer:longPressGest];
}

#pragma mark - 方法
- (void)updateUI {
    self.updateItemView.subTitleTextField.hidden = false;
    self.updateItemView.subTitleTextField.textColor = UIColor.mj_redColor;
    self.updateItemView.subTitleTextField.mj_localizable = @"New Version";
}
-(void)longPressView:(UILongPressGestureRecognizer *)longPressGest{

    NSLog(@"%ld",longPressGest.state);
    if (longPressGest.state==UIGestureRecognizerStateBegan) {
        self.tokenLabel.text = UserManager.shared.userToken;
        NSLog(@"长按手势开启");
    } else {
        NSLog(@"长按手势结束");
    }
    
}

- (void)requestData{
    
}

- (IBAction)handleUpdateSecurityButtonEvent:(UIButton *)sender {
   
    if(self.updateData){
        UpdateController *vc = [[UpdateController alloc]init];
        vc.updateData = self.updateData;
        [self.navigationController pushViewController:vc animated:true];
    }else{
        MJUIAlertViewConfigure *configure = [[MJUIAlertViewConfigure alloc]init];
        configure.confirmButtonColor = UIColor.mj_appColor;
        configure.confirmTitle = MJUILocalizedString(@"OK_qd");
        configure.hiddenCancelButton = true;
        configure.messageAlignmentCenter = true;
        
        NSString *version = [NSString mj_appVersion];
        NSString *messageString = [NSString stringWithFormat:@"%@ %@ %@",MJUILocalizedString(@"The version"),version,MJUILocalizedString(@"is the latest")];
        [MJUIAlertView alertViewWithTitle:MJUILocalizedString(@"No updates available") message:messageString configure:configure confirmBlock:^{
            
        } cancelBlock:^{

        }];
    }
    
}
#pragma mark - 代理

#pragma mark - 懒加载

@end
